// mircoApp/assessment/assessmentIndex/assessmentIndex.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    first_cat_list: [],
    second_cat_list: [],
    third_cat_list: [],
    first_cat_id: null,
    second_cat_id: null,
    third_cat_id: null,
    postLoading: false,
    info:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.init();
    this.getData();
  },
  init() {
    this.setData({
      first_cat_id: null,
      second_cat_id: null,
      third_cat_id: null,
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  toRecord() {
    wx.navigateTo({
      url: '/mircoApp/assessment/assessment_questionnaire_record/assessment_questionnaire_record',
    })
  },
  toQuestionnaire() {
    if (!this.data.third_cat_id || !this.data.second_cat_id || !this.data.first_cat_id) {
      this.$toast("请先选择分类");
      return;
    }
    wx.navigateTo({
      url: '/mircoApp/assessment/assessment_questionnaire/assessment_questionnaire?id=' + this.data.third_cat_id,
    })
  },
  tapClass(e) {
    let {
      item,
      key
    } = e.currentTarget.dataset;
    console.log(item, key);
    if (this.data.postLoading) {
      app.tips('请求中请稍后');
      return;
    }
    if (key == "first") {
      this.setData({
        first_cat_id: item.id
      })
    } else if (key == "second") {
      this.setData({
        second_cat_id: item.id
      })
    } else {
      this.setData({
        third_cat_id: item.id
      })
    }
    this.getData();
  },
  getData() {
    this.data.postLoading = true;
    let json = {};
    if (this.data.first_cat_id) {
      json.first_cat_id = this.data.first_cat_id;
    }
    if (this.data.second_cat_id) {
      json.second_cat_id = this.data.second_cat_id;
    }
    if (this.data.third_cat_id) {
      json.third_cat_id = this.data.third_cat_id;
    }
    app._getNetWork({
      url: app.getNetAddresss("plugin.assessment.frontend.question.categoryList"),
      data: json,
      success: (resdata) => {
        this.data.postLoading = false;
        let res = resdata.data;
        if (res.result == 1) {
          this.setData({
            first_cat_list: res.data.first_cat_list,
            second_cat_list: res.data.second_cat_list,
            third_cat_list: res.data.third_cat_list,
            first_cat_id: res.data.first_cat_id,
            second_cat_id: res.data.second_cat_id,
            third_cat_id: res.data.third_cat_id,
            info:res.data
          })
        } else {
          app.tips(res.msg);
        }
      },
      fail: (err) => {
        this.data.postLoading = false;
      }
    });
  }
})